package cn.stock.controller;

import cn.stock.entity.Stock;
import cn.stock.service.StockServiceImpl;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author summit
 * @since 2022/5/27 15:09
 */
@RestController
@Slf4j
public class StockController {

    @Autowired
    private StockServiceImpl stockService;


    @GetMapping("/stock")
    @Transactional
    public void stock(@RequestParam Long productId) {
        log.info("库存[{}]减一", productId);
        Stock byId = stockService.getById(1L);
        byId.setCount(byId.getCount()-1);
        stockService.updateById(byId);
    }

}
